package com.gxa.jd.controller;

import com.gxa.jd.pojo.Room;
import com.gxa.jd.service.RoomService;
import com.gxa.entity.PageResult;
import com.gxa.entity.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@RestController
@RequestMapping("/room")
public class RoomController {

    @Autowired
    private RoomService roomService;

    @GetMapping("/findAll")
    @ApiOperation(value = "查询所有房型",notes = "查询所有房型")
    public List<Room> findAll() {
        return roomService.findAll();
    }

    @GetMapping("/findPage")
    @ApiOperation(value = "分页查询",notes = "分页查询")
    public PageResult<Room> findPage(int page, int size) {
        return roomService.findPage(page, size);
    }

    @PostMapping("/findList")
    public List<Room> findList(@RequestBody Map<String, Object> searchMap) {
        return roomService.findList(searchMap);
    }

    @PostMapping("/findPage")
    public PageResult<Room> findPage(@RequestBody Map<String, Object> searchMap, int page, int size) {
        return roomService.findPage(searchMap, page, size);
    }

    @GetMapping("/findById")
    @ApiOperation(value = "根据id查询房型信息",notes = "根据id查询房型信息")
    public Room findById(Long id) {
        return roomService.findById(id);
    }


    @PostMapping("/add")
    @ApiOperation(value = "添加房型信息",notes = "添加房型信息")
    public Result add(@RequestBody Room room) {
        roomService.add(room);
        return new Result();
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改房型信息",notes = "修改房型信息")
    public Result update(@RequestBody Room room) {
        roomService.update(room);
        return new Result();
    }

    @GetMapping("/delete")
    @ApiOperation(value = "根据id删除房型",notes = "根据id删除房型")
    public Result delete(Long id) {
        roomService.delete(id);
        return new Result();
    }

}
